﻿using Reactor.Environment;
using Reactor.Messages.Events.Endpoint;
using Reactor.Messaging.Attributes;

namespace Reactor.Messaging.ServiceBus
{
    [PubSubChannel]
    public class EndpointSubscriptionChangedHandler : IMessageHandler<EndpointSubscriptionChanged>
    {
        #region Implementation of IMessageHandler<EndpointSubscriptionChanged>

        /// <summary>
        /// Handles the message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="messageContext">Context provided with message deliver</param>
        public void Handle(EndpointSubscriptionChanged message, IMessageContext messageContext)
        {
            if (message.EndpointName == Context.ServiceBus.Configuration.CurrentEndpointInputChannel.DestinationName) return;

            Context.ServiceBus.Configuration.DestinationRegistry.LookupSubscriberByName(message.EndpointName);
        }

        #endregion
    }
}
